<#import "/common/function.ftl" as fn>
<@fn.header _title="核对家庭成员基本信息">
    <script language="javascript" type="text/javascript" src="${base}/web/js/My97DatePicker/WdatePicker.js"></script>
	<script language="javascript" type="text/javascript" src="${base}/web/js/jquery.form.js"></script>
    <script language="javascript" type="text/javascript">
        function openNewDiv(id) {
            //mask遮罩层
            var newMask = document.createElement("div");
            newMask.id = "mask";
            newMask.style.position = "absolute";
            newMask.style.zIndex = "1";
            newMask.style.width = document.body.clientWidth + "px";
            newMask.style.height = document.body.clientHeight + "px";
            newMask.style.top = "0px";
            newMask.style.left = "0px";
            newMask.style.background = "#33393C";
            newMask.style.filter = "alpha(opacity=40)";
            newMask.style.opacity = "0.50";
            document.body.appendChild(newMask);
            //新弹出层
            var newDiv = document.getElementById(id);
            newDiv.style.display = "block";
            newDiv.style.position = "absolute";
            newDiv.style.zIndex = "9999";
            newDiv.style.background = "#EFEFEF";
            document.documentElement.style.overflow = 'hidden'; //去除页面滚动条
            autoMargin(id);
            $("select").hide();
            $("#category").show();
            $("#fileAttr").show();
            $("#giveBack").show();
        }
        function CloseMast(id) {
            try {
                document.body.removeChild(document.getElementById("mask"));
                document.getElementById(id).style.display = "none";
                $("select").show();
                document.documentElement.style.overflow = 'auto';
            } catch(e) {}
        }

        function autoMargin(id) {
            var mainEle = document.getElementById(id);
            mainEle.style.left = (document.body.clientWidth - mainEle.style.width.substr(0, 3)) / 2 + "px";
            mainEle.style.top = (document.body.clientHeight - mainEle.style.height.substr(0, 3)) / 2 + "px";
        }

        function selectFile() {
            var fileName = File1.value;
            var size = File1.size;
            var state = "待传";
            // btnDeleteRow();
            var rownum = $("#uploadfile tr").length - 1;
            var row = "<tr><td>" + fileName + "</td><td>" + size + "</td><td>" + state + "</td></tr>";
            $(row).insertAfter($("#uploadfile tr:eq(" + rownum + ")"));
        }

        function btnDeleteRow() {
            $("#uploadfile tr").each(function(i) {
                if (i != 0) {
                    $(this).remove();
                }
            });
        }
    </script>
    <script language="javascript" type="text/javascript">
        function showTable() {
            $("#table2").toggle(200);
        }
        function showPerson(personId) {
            <#list familyMembers as data>
            if(personId=='${data.id}'){
                $("#familyMemberIdType").val("${data.idType}");
                $("#familyMemberIdNumber").val(${data.idNumber});
                $("#familyMemberName").val("${data.name}");
                $("#familyMemberGender").val("${data.gender}");
                $("#familyMemberNation").val("${data.nation}");
                $("#familyMemberId").val("${data.id}");
                <#if data.birthday!=null>
                	$("#familyMemberBirthday").val("${(data.birthday)?string('yyyy-MM-dd')}");
                </#if>
                $("#familyMemberPoliticalStatus").val("${data.politicalStatus}");
                $("#familyMemberMaritalStatus").val("${data.maritalStatus}");
               	$("#familyMemberRelationMainApplicant").val("${data.relationMainApplicant}");
               	$("#familyMemberPhone").val("${data.phone}");
               	$("#familyMemberMobile").val("${data.mobile}");
               	$("#familyMemberZip").val("${data.zipCode}");
               	
               	$("#familyMemberHouseholdDistrictCode").val("${data.householdDistrictCode}");
               	$("#familyMemberHouseholdType").val("${data.householdType}");
               	$("#familyMemberLivingDistrictCode").val("${data.livingDistrictCode}");
               	$("#familyMemberLivingAddress").val("${data.livingAddress}");
               	<#if data.startDateLiving!=null>
                	$("#familyMemberStartDateLiving").val("${(data.startDateLiving)?string('yyyy-MM-dd')}");
                </#if>
                $("#familyMemberEducation").val("${data.education}");
                $("#familyMemberHealthStatus").val("${data.healthStatus}");
                
                $("#familyMemberLaborLossStatus").val("${data.laborLossStatus}");
                $("#familyMemberDisabilityDegree").val("${data.disabilityDegree}");
                $("#familyMemberDiseaseName").val("${data.diseaseName}");
            }
            </#list>
        }
        
        function saveFamilyMemberInfo() {
			if(!Validator.Validate($("#familyMemberForm").get(0))){
		    	return false;
		    }
		    var url = "${base}/infoInput/updateFamilyMemberInfo/";
		    $.ajax({
		           type: "POST",
		           url: url,
		           data: $("#familyMemberForm").serialize(),
		           error: function()
		           {
		               alert("出错啦！");
		           },
		           success: function(data)
		           {
		                if(data.result){
			               alert("保存成功！");
			               $(".visited").find("a")[0].click();
			            }else{
			               alert("保存失败，请将表单信息填写完整！");
			            }
		           }
		         });
		}
		
		function deleteFamilyMemberInfo(id){
			var url = "${base}/infoInput/deleteFamilyMemberInfo/"+id;
		    $.ajax({
		           type: "GET",
		           url: url,
		           data: $("#familyMemberForm").serialize(),
		           error: function()
		           {
		               alert("出错啦！");
		           },
		           success: function(data)
		           {
		               if(data.result){
			               		alert("删除成功！");
		               			$(".visited").find("a")[0].click();
			               }else{
			               		alert("出错啦，请检查！");
			               }
		           }
		  });
		}
    </script>
    <script language="javascript" type="text/javascript">
		$(document).ready(function() { 
		    var options = {
		        beforeSubmit:validate,
		        success:showResponse,
		        type:'post',
		        url:'${base}/infoInput/upload'
		    }; 
		    
		    $("#uploadForm").submit(function() {
		        $(this).ajaxSubmit(options);
		        return false;
		    });
		}); 
		
		function validate(formData, jqForm, options) {
		    for (var i=0; i < formData.length; i++) { 
		        if (!formData[i].value) { 
		            alert('请将表单信息填写完整！'); 
		            return false; 
		        }
		    }
		    return true; 
		}
		
		var fileId = 0;
		function showResponse(responseText, statusText, xhr, $form)  {
//			alert("返回数据："+responseText['status']);
			if(responseText['status']=="1"){
//				alert("上传成功！");
				var tr = "";
	            tr += '<tr id="fileTr'+responseText['enclosure']['id']+'">';
	            tr += '<td name="tdFileNum" style="width:50px"></td>';
	            tr += '<td>'+$("#fileName").val()+'</td>';
	            tr += '<td>'+$("#fileNum").val()+'</td>';
	            tr += '<td>'+$("#filePage").val()+'</td>';
	            tr += '<td>'+$("#category").find("option:selected").text()+'</td>';
	            tr += '<td>'+$("#fileAttr").find("option:selected").text()+'</td>';
	            tr += '<td>'+$("#giveBack").find("option:selected").text()+'</td>';
	            tr += '<td><a href="javascript:void(0);" onclick="delFile(\''+responseText['enclosure']['id']+'\')">删除</a></td>';
	            tr += '</tr>';
//	            alert(tr);
	            CloseMast("divDetail");
//	            $form.reset();
				$("#fileName").val("");
				$("#fileNum").val("");
				$("#filePage").val("");
				$("#category").val("");
				$("#fileAttr").val("原件");
				$("#giveBack").val("");
				$("#upfile").val("");
				fileId +=1;
				$("#addFileTr").before(tr);
				refreshTdNum();
			}else{
				alert("上传失败！系统或网络错误！");
			}
		}
		
		function	delFile(id){
			$.get("${base}/infoInput/delete/${(mainfm.id)!}/"+id, function(data){
				if(data['status']=="1"){
					$("tr").remove("#fileTr"+id);
					refreshTdNum();
				}else{
					alert("删除失败！");
				}
			}, "json");
		}
		
		function refreshTdNum(){
			$("td[name='tdFileNum']").each(function(i){
				$(this).text(i+1);
			});
		}
    </script>
</@fn.header>

<body>
    <div class="rightBk">
        <@fn.position _value="信息录入 &gt;&gt; 核对家庭成员基本信息" />
        <!-- 选项卡 -->
        <div style="margin:0px 0;height:30px">
            <ul class="tab">
                <li><a href="${base}/infoInput/familyBasicInfo/${checkTotalId}/${taskId?c}/${result}">核对家庭基本信息</a></li>
		    	<li class="visited"><a href="${base}/infoInput/familyMemberInfo/${checkTotalId}/${taskId?c}/${result}">核对家庭成员基本信息</a></li>
		    	<li><a href="${base}/infoInput/familyMemberIncome/${checkTotalId}/${taskId?c}/${result}">家庭成员可支配收入</a></li>
		   	 	<li><a href="${base}/infoInput/familyMemberProperty/${checkTotalId}/${taskId?c}/${result}">家庭成员财产</a></li>
		    	<li><a href="${base}/infoInput/sendCheck/${checkTotalId}/${taskId?c}/${result}">发送信息核实</a></li>   
            </ul>
        </div>
        <div class="title">
            <div class="title-middle">
                <div class="title-left">
                </div>
                <div class="title-caption">
                    核对家庭成员信息概要
                </div>
                <div class="title-right">
                </div>
                <div style="float:right;">
                	<a href="${base}/infoInput/familyMemberInfo/${checkTotalId}/${taskId?c}/${result}"><img src="${base}/web/img/add.gif" style="margin:8px 0 0 0; border:0px;" /></a>
                </div>
            </div>
        </div>
        <!-- table -->
        <table class="tableCenter">
            <tr>
                <th width="8%">
                    序号
                </th>
                <th>
                    姓名
                </th>
                <th width="17%">
                    与申请人代表关系
                </th>
                <th width="25%">
                    证件号
                </th>
                <th width="20%">
                    申请人类型
                </th>
               <th width="10%">
                    操作
                </th>
            </tr>
            <#list familyMembers as fm>
                <tr>
                    <td>
                        ${fm_index+1}
                    </td>
                    <td>
                        <a href="#" onclick="showPerson('${fm.id}');">
                            ${fm.name}
                        </a>
                    </td>
                    <td>
                        ${fm.relationMainApplicant}
                    </td>
                    <td>
                        ${fm.idNumber}
                    </td>
                    <td>
                        共同申请人
                    </td>
                    <td>
                        <a href="#" onclick="deleteFamilyMemberInfo('${fm.id}')">删除</a>
                    </td>
                </tr>
            </#list>
        </table>
        <br />
        <!-- title -->
        <div class="title">
            <div class="title-middle">
                <div class="title-left">
                </div>
                <div class="title-caption">
                    家庭成员基本信息
                </div>
                <div class="title-right">
                </div>
            </div>
        </div>
        <!-- table -->
        <form action="${base}/infoInput/updateFamilyMemberInfo/" method="POST" name="familyMemberForm" id="familyMemberForm">
        <table class="table1">
            <colgroup class="GridCaption" style="width:12%; background-color: #eef3f7;" ></colgroup>
            <colgroup style="width: 20%;" ></colgroup>
            <colgroup class="GridCaption" style="width:12%; background-color: #eef3f7;" ></colgroup>
            <colgroup style="width: 20%;" ></colgroup>
            <colgroup class="GridCaption" style="width:12%; background-color: #eef3f7;" ></colgroup>
            <colgroup style="width: 20%;" ></colgroup>
            <tr>
            	<td>申请人姓名</td>
                <td>
                	<input name="familyMemberName" id="familyMemberName" type="text" class="input4" value="" require="true" dataType="Limit" min="1" max="50" msg="长度为1~50" />
                </td>
            	<td>证件类型</td>
           		<td>
	            <select name="familyMemberIdType" id="ddlCertType0" class="select1">
	                	<#list idTypes as idType>
                        	<option value="${idType.code}">${idType.name}</option>
                    	</#list>
            	</select>
            	</td>
            	<td>证件号</td>
            	<td><input name="familyMemberIdNumber" type="text" id="familyMemberIdNumber" class="input4" value="" require="true" dataType="Limit" min="1" max="50" msg="长度为1~50" /></td>
            </tr>
            <tr>
                <td>性别</td>
           		<td>
		            <select name="familyMemberGender" id="familyMemberGender" class="select1">
		                <option value="01" selected="selected">男</option>
		                <option value="02">女</option>
	            	</select>
            	</td>
                <td>民族</td>
                <td>
                    <select name="familyMemberNation" id="familyMemberNation" class="select1">
                        <#list nations as nation>
                        	<option value="${nation.code}">${nation.name}</option>
                    	</#list>
                    </select>
                </td>
                <td>出生日期</td>
                <td><input name="familyMemberBirthday" id="familyMemberBirthday" type="text" class="input4" onClick="WdatePicker()" require="true" dataType="Require" msg="填写不正确" readonly="readonly" /></td>
            </tr>
            <tr>
                <td>政治面貌</td>
                <td>
                    </select><select name="familyMemberPoliticalStatus" id="familyMemberPoliticalStatus" class="select1">
                    	<#list politicalStatusList as _politicalStatus>
                        	<option value="${_politicalStatus.code}">${_politicalStatus.name}</option>
                    	</#list>
                    </select>
                <td>婚姻状况 </td>
                <td>
                    </select><select name="familyMemberMaritalStatus" id="familyMemberMaritalStatus" class="select1">
                        <#list maritalStatusList as maritalStatus>
                        	<option value="${maritalStatus.code}">${maritalStatus.name}</option>
                    	</#list>                     
                    </select>
                </td>
                <td>与主申请人关系 </td>
                <td>
                    </select><select name="familyMemberRelationMainApplicant" id="familyMemberRelationMainApplicant" class="select1">
                        <#list relaitionList as rl>
                        	<option value="${rl.name}">${rl.name}</option>
                    	</#list>                     
                    </select>
                </td>
            </tr>
            
            <tr>
			    <td>固定电话</td>
                <td>
                	<input name="familyMemberPhone" type="text" id="familyMemberPhone" class="input4" value="" require="true" dataType="Phone" msg="填写不正确" />
                </td>
                <td>移动电话 </td>
                <td>
                	<input name="familyMemberMobile" type="text" id="familyMemberMobile" class="input4" value="" require="true" dataType="Mobile" msg="填写不正确" />
                </td>
                <td>邮政编码</td>
                <td><input name="familyMemberZip" id="familyMemberZip" type="text" class="input4" require="true" dataType="Zip" msg="填写不正确" /></td>
            </tr>            
            <tr>
                <td>户籍所在地</td>
                <td colspan="3">
                    <select id="Select6" class="select1">
                        <option selected="selected" value="01">沈阳市</option>
                    </select>
                    <select name="familyMemberHouseholdDistrictCode" id="familyMemberHouseholdDistrictCode" class="select1">
                      <#list citys as city>
                        	<option value="${city.code}">${city.name}</option>
                      </#list>
                    </select>
 	                派出所
                </td>
                <td>户籍类型</td>
           		<td>
	            <select name="familyMemberHouseholdType" id="familyMemberHouseholdType" class="select1">
	            	<#list householdTypes as type>
	                	<option value="${type.code}">${type.name}</option>
	                </#list>
            	</select>
            	</td>
            </tr>       
            <tr>
                <td>现居住地址 </td>
                <td colspan="4">
                    <select id="addrCity" class="select1">
                        <option selected="selected" value="01">沈阳市</option>
                    </select>
                    <select id="addrArea" class="select1">
                      <#list citys as city>
                        	<option value="${city.code}">${city.name}</option>
                      </#list>
                    </select>
                    <select name="familyMemberLivingDistrictCode" id="familyMemberLivingDistrictCode" class="select1">
                      <#list streets as street>
                        	<option value="${street.code}">${street.name}</option>
                      </#list>
                    </select>
                    <input name="familyMemberLivingAddress" type="text" id="familyMemberLivingAddress" class="input4" onclick="this.select()" value="" require="true" dataType="Limit" min="1" max="50" msg="长度为1~50" />
                </td>
            </tr>

            <tr>
                <td>现居住地开始居住时间</td>
                <td>
	                 <input name="familyMemberStartDateLiving" type="text" id="familyMemberStartDateLiving" class="input4" value="" onClick="WdatePicker()" require="true" dataType="Require" msg="填写不正确" readonly="readonly" />
                </td>
                <td>文化程度 </td>
                <td>
                	<select name="familyMemberEducation" id="familyMemberEducation" class="select1">
                      <#list educations as education>
                      	<option value="${education.code}">${education.name}</option>
                      </#list>
                    </select>
               </td>
               <td>健康状况</td>
                <td>
                	<input name="familyMemberHealthStatus" type="text" id="familyMemberHealthStatus" class="input4" value="" require="true" dataType="Limit" min="1" max="50" msg="长度为1~50" />
                </td>
            </tr>

            <tr>
                <td>劳动能力丧失状况</td>
                <td>
                <select name="familyMemberLaborLossStatus" id="familyMemberLaborLossStatus" class="select1">
	                <#list laborlost as ll>
	                	<option value="${ll.code}">${ll.name}</option>
	                </#list>
                </select>
                </td>
                <td>残疾等级</td>
           		<td>
	            <select name="familyMemberDisabilityDegree" class="select1" id="familyMemberDisabilityDegree">
	            	<#list disabilityDegreeList as dd>
	                	<option value="${dd.code}">${dd.name}</option>
	                </#list>
            	</select>
            	</td>
                <td>所患主要疾病名称</td>
                <td><input name="familyMemberDiseaseName" id="familyMemberDiseaseName" type="text" class="input4" require="true" dataType="Limit" min="1" max="50" msg="长度为1~50" /></td>
            </tr>
    	</table>
        <input type="hidden" id="familyMemberId" name="familyMemberId" value=""/>
        <input type="hidden" name="checkTotalId" value="${checkTotalId}"/>
        </form>
        <br />
        <!-- title -->
    	<div class="title marginTop15">
            <div class="title-middle">
                <div class="title-left">
                </div>
                <div class="title-caption">
                    证明材料
                </div>
                <div class="title-right">
                </div>
            </div>
        </div>
        <!-- table -->
        <table class="table1">
            <tr>
                <th width="5%">序号</th>
                <th>材料名称</th>
                <th width="10%">份数</th>
                <th width="10%">页数</th>
                <th width="10%">文件类型</th>
                <th width="10%">文件属性</th>
                <th width="10%">归还</th>
                <th width="5%">操作</th>
            </tr>
            <#list enclosurelist as data>
            <tr id="fileTr${(data.id)!}">
                <td name="tdFileNum" style="width:50px">${data_index+1}</td>
                <td>${(fileName)!}</td>
                <td>${(data.fileNum)!}</td>
                <td>${(data.filePage)!}</td>
                <td>${(data.category)!}</td>
                <td>${(data.fileAttr)!}</td>
                <td>${(data.giveBack)!}</td>
                <td><a href="javascript:void(0);" onclick="delFile('${(data.id)!}')">删除</a></td>
            </tr>
           </#list>      
            <tr id="addFileTr">
            	<td colspan="8"><img src="${base}/web/img/btnAddCl.gif" alt="" onclick='openNewDiv("divDetail");'/></td>
            </tr>
        </table>
        <!-- button -->
        <div class="marginTop15 alignCenter">
            <img src="${base}/web/img/btnSave.gif" alt="" onclick="saveFamilyMemberInfo();"/>
        <!--    <img src="${base}/web/img/btnCancel.gif" alt="" />
            <img src="${base}/web/img/btnLast.gif" alt="" />
            <img src="${base}/web/img/btnNext.gif" alt="" />-->
        </div>
        <div id="tools">
            <div class="materialsDiv" id="divDetail" style="display:none; width: 850px;">
                <div class="materialsTitle">
                    <div class="materialsTitleL">
                        上传材料
                    </div>
                    <div class="materialsTitleR">
                        <a href="#">
                            <img src="${base}/web/img/close.gif" border="0" onclick='CloseMast("divDetail");' />
                        </a>
                    </div>
                </div>
                <div>
	                <form name="uploadForm" id="uploadForm" enctype="multipart/form-data">
                		<input type="hidden" name="fmId" value="${(mainfm.id)!}" />
	                    <table class="materialsGrid">
	                        <tr style="height: 20px;">
	                            <th>材料名称</th>
	                            <th>份数</th>
	                            <th>页数</th>
	                            <th>文件类型</th>
	                            <th>文件属性</th>
	                            <th>归还</th>
	                            <th>材料</th>
	                        </tr>
	                        <tr>
	                        	<td><input name="fileName" id="fileName" type="text" style="width:160px" /></td>
	                        	<td><input name="fileNum" id="fileNum" type="text" style="width:40px" /></td>
	                        	<td><input name="filePage" id="filePage" type="text" style="width:40px" /></td>
	                        	<td><select name="category" id="category" class="select1" style="width:100px"><option value="">请选择</option><#list enclosures as opt><option value="${opt.name}">${opt.name}</option></#list></select></td>
	                        	<td><select name="fileAttr" id="fileAttr" class="select1" style="width:65px"><option value="原件">原件</option><option value="复印件">复印件</option></select></td>
	                        	<td><select name="giveBack" id="giveBack" class="select1" style="width:70px"><option value="">请选择</option><option value="是">是</option><option value="否">否</option></select></td>
	                        	<td><input type="file" name="upfile" id="upfile" /></td>
	                        </tr>
	                        <tr>
	                            <td colspan="7"><input type="image" src="${base}/web/img/btnUpload.gif" /></td>
	                        </tr>
	                    </table>
	                </form>
                </div>
            </div>
        </div>
    </div>
</body>
</html>